package mywebapp.tools.jsf;

import mywebapp.impl.*;
import mywebapp.dao.*;
import mywebapp.webpage.*;

public class FACES_NAVIGATION_JSF
{
  protected static String nl;
  public static synchronized FACES_NAVIGATION_JSF create(String lineSeparator)
  {
    nl = lineSeparator;
    FACES_NAVIGATION_JSF result = new FACES_NAVIGATION_JSF();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<navigation-rule>" + NL + "\t<display-name>";
  protected final String TEXT_2 = "</display-name>" + NL + "\t<from-view-id>/";
  protected final String TEXT_3 = ".jsp</from-view-id>" + NL + "\t<navigation-case>" + NL + "\t\t<from-outcome>success</from-outcome>" + NL + "\t\t<to-view-id>/";
  protected final String TEXT_4 = ".jsp</to-view-id>" + NL + "\t</navigation-case>" + NL + "</navigation-rule>";
  protected final String TEXT_5 = NL + "<navigation-rule>" + NL + "\t<display-name>";
  protected final String TEXT_6 = "</display-name>" + NL + "\t<from-view-id>/";
  protected final String TEXT_7 = ".jsp</from-view-id>" + NL + "\t<navigation-case>" + NL + "\t\t<from-outcome>success</from-outcome>" + NL + "\t\t<to-view-id>/";
  protected final String TEXT_8 = ".jsp</to-view-id>" + NL + "\t</navigation-case>" + NL + "</navigation-rule>" + NL + "<navigation-rule>" + NL + "\t<display-name>";
  protected final String TEXT_9 = "</display-name>" + NL + "\t<from-view-id>/";
  protected final String TEXT_10 = ".jsp</from-view-id>" + NL + "\t<navigation-case>" + NL + "\t\t<from-outcome>failed</from-outcome>" + NL + "\t\t<to-view-id>/error.jsp</to-view-id>" + NL + "\t</navigation-case>" + NL + "</navigation-rule>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     BaliseComposite balise = (BaliseComposite) argument; 
    
	if(balise instanceof A)
	{
		A a = (A) balise;

    stringBuffer.append(TEXT_1);
    stringBuffer.append(a.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_2);
    stringBuffer.append(a.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_3);
    stringBuffer.append(a.getHref().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_4);
    }
    
	if(balise instanceof Form)
	{
		Form f = (Form) balise;

    stringBuffer.append(TEXT_5);
    stringBuffer.append(f.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(f.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(f.getNext().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(f.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_9);
    stringBuffer.append(f.getPage().getName().toLowerCase().replaceAll(" ", "_"));
    stringBuffer.append(TEXT_10);
    } 
    return stringBuffer.toString();
  }
}
